package com.base.controller;

import com.base.service.EmpiAlgorithmConfigService;
import com.base.service.EmpiWeightConfigService;
import com.base.utils.Result;
import com.base.utils.ResultUtil;
import com.base.vo.EmpiAlgorithmConfig;
import com.base.vo.EmpiWeightConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 规则配置Controller层
 *
 * @author wnhuang
 * @Package com.base.controller
 * @date 2021-02-07 0:11
 */
@RestController
@RequestMapping(value = "/weightConfig")
public class EmpiWeightConfigController {
    @Autowired
    EmpiWeightConfigService weightConfigService;

    @Autowired
    EmpiAlgorithmConfigService empiAlgorithmConfigService;

    @GetMapping("/getAll")
    public Result getAll() {
        return ResultUtil.success(weightConfigService.list());
    }

    @PostMapping("save")
    public Result saveWeightConfig(@RequestBody EmpiWeightConfig EmpiWeightConfig) {
        return ResultUtil.success(weightConfigService.saveOrUpdate(EmpiWeightConfig));
    }

    @PostMapping("saveField")
    public Result saveWeightConfigField(@RequestBody EmpiAlgorithmConfig empiAlgorithmConfig) {
        return ResultUtil.success(empiAlgorithmConfigService.saveOrUpdate(empiAlgorithmConfig));
    }

    @DeleteMapping("/delete/{id}")
    public Result saveWeightConfig(@PathVariable String id) {
        return ResultUtil.success(weightConfigService.removeById(id));
    }

    @DeleteMapping("/deleteField/{id}")
    public Result delWeightConfigField(@PathVariable String id) {
        return ResultUtil.success(empiAlgorithmConfigService.removeById(id));
    }
}
